package com.flex.controller;
import com.flex.dto.AccountDTO;
import com.flex.entity.Account;
import com.flex.service.AccountService;
import com.flex.util.BaseResult;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

@Api("AdminController类接口")
@RestController
@RequestMapping("/admin")
@Validated
public class AdminController {

    @Autowired
    AccountService accountService;

    @GetMapping(value = "/list")
    @ApiOperation(value = "1-查看所有列表")
    public BaseResult<List<Account>> getList(){
        List<Account> accountList = accountService.getAllAccountList();
        return BaseResult.successResult(accountList);
    }

    @PutMapping(value = "/account")
    @ApiOperation(value = "2-添加账户")
    public BaseResult addAccount(@Validated @RequestBody AccountDTO accountDTO){
        return BaseResult.successResult(accountService.insertAccount(accountDTO));
    }

    @PostMapping(value = "/account")
    @ApiOperation(value = "3-根据ID修改账户名称")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "主键"),
            @ApiImplicitParam(name = "name",value = "名称")
    })
    public BaseResult updateAccountById(@NotNull String id, @NotBlank String name){
        return BaseResult.successResult(accountService.updateAccountById(id,name));
    }

    @DeleteMapping(value = "/account/{id}")
    @ApiOperation(value = "4-根据ID删除商户信息")
    public BaseResult deletedAccount(@NotNull @PathVariable(value = "id") String id){
        return BaseResult.successResult(accountService.deleteAccountById(id));
    }

    @PostMapping(value = "/getFile")
    @ApiOperation(value = "5-获取excel文件")
    public BaseResult getExcelFile(){
        return BaseResult.successResult();
    }
}